//查出用户加入购物车的信息数量
	$(function(){
		try {
			$(".shopper_nums").html(JSON.parse(getCookieJsonData("SHOPPING_LIST")).length);
		} catch (e) {
			$(".shopper_nums").html(0);
		}
		
	});
	//json格式返回cookie中的数据
	function getCookieJsonData(key){
		var cookies=document.cookie;
		var cookie_pos = cookies.indexOf(key)+key.length + 1;
		var cookie_end = cookies.indexOf(";", cookie_pos); 
		var shoppingJson="";
		if(cookie_end==-1){
			shoppingJson=decodeURIComponent(cookies.substring(cookie_pos));
		}else{
			shoppingJson=decodeURIComponent(cookies.substring(cookie_pos, cookie_end));
		}
		return shoppingJson;
	}

window.onload = function(){
	(function() {
		var docElem = window.document.documentElement, didScroll, scrollPosition;

		// trick to prevent scrolling when opening/closing button
		function noScrollFn() {
			alert(1);
			window.scrollTo( scrollPosition ? scrollPosition.x : 0, scrollPosition ? scrollPosition.y : 0 );
		}

		function noScroll() {
			window.removeEventListener( 'scroll', scrollHandler );
			window.addEventListener( 'scroll', noScrollFn );
		}

		function scrollFn() {
			window.addEventListener( 'scroll', scrollHandler );
		}

		function canScroll() {
			window.removeEventListener( 'scroll', noScrollFn );
			scrollFn();
		}

		function scrollHandler() {
			if( !didScroll ) {
				didScroll = true;
				setTimeout( function() { scrollPage(); }, 60 );
			}
		};

		function scrollPage() {
			scrollPosition = { x : window.pageXOffset || docElem.scrollLeft, y : window.pageYOffset || docElem.scrollTop };
			didScroll = false;
		};

		scrollFn();

		[].slice.call( document.querySelectorAll( '.morph-button' ) ).forEach( function( bttn ) {
			new UIMorphingButton( bttn, {
				closeEl : '.icon-close',
				onBeforeOpen : function() {
					// don't allow to scroll
					noScroll();
				},
				onAfterOpen : function() {
					// can scroll again
					canScroll();
				},
				onBeforeClose : function() {
					// don't allow to scroll
					noScroll();
				},
				onAfterClose : function() {
					// can scroll again
					canScroll();
				}
			} );
		} );

		// for demo purposes only
		[].slice.call( document.querySelectorAll( 'form button' ) ).forEach( function( bttn ) { 
			bttn.addEventListener( 'click', function( ev ) {ev.preventDefault(); } );
		} );
	})();
	
}


